﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL;
using Model;

namespace DAL
{
    public class JointingCheck : BaseRepository_DT<JointingCheckInfo>, IJointingCheck
    {
        #region 静态变量部分
        private const string PARM_JOINTINGCHECK_PRODUCTSN = "@ProductSN";
        private const string PARM_JOINTINGCHECK_RECORDTIME = "@RecordTime";
        private const string PARM_JOINTINGCHECK_USERID = "@UserID";
        private const string PARM_JOINTINGCHECK_FAILURENAME = "@FailureName";
        private const string PARM_JOINTINGCHECK_RESPONSEUSER = "@ResponseUser";

        private const string PARM_JOINTINGCHECK_PRODUCTTYPEID = "@ProductTypeID";
        #endregion

        #region 数据检索部分
        public IList<JointingCheckInfo> LoadEntities()
        {
            return null;
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public JointingCheckInfo LoadEntity<T1>(T1 productSN)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = productSN;
            return ExcuteSqlToGetEntity("JointingCheck_selectLastbySN", parm);
        }

        public IList<JointingCheckInfo> GetJointingChecksbySN(string productSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("JointingCheck_selectbySN", parm);
        }

        public IList<JointingCheckInfo> GetJointingChecksbyDT(DateTime starttime, DateTime stoptime)
        {
            SqlParameter[] parms = GetDTParameters();
            parms[0].Value = starttime;
            parms[1].Value = stoptime;
            return ExcuteSqlToGetEntities("JointingCheck_selectbyDT", parms);
        }

        public IList<JointingCheckInfo> GetJointingChecksbyPIDDT(string productTypeID, DateTime starttime, DateTime stoptime)
        {
            SqlParameter[] parms = GetPIDDTParameters();
            parms[0].Value = productTypeID;
            parms[1].Value = starttime;
            parms[2].Value = stoptime;
            return ExcuteSqlToGetEntities("JointingCheck_selectbyPIDDT", parms);
        }
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override JointingCheckInfo GetEntityRecord(SqlDataReader rdr)
        {
            JointingCheckInfo pro = new JointingCheckInfo(rdr.GetValue(0).ToString(), rdr.GetDateTime(1), rdr.GetValue(2).ToString()
                , rdr.GetValue(3).ToString(), rdr.GetValue(4).ToString(), rdr.GetValue(5).ToString());
            return pro;
        }

        public override JointingCheckInfo GetEntityRecord()
        {
            JointingCheckInfo pro = new JointingCheckInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "JointingCheck_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_JOINTINGCHECK_PRODUCTSN, SqlDbType.NVarChar, 50);
            return Parm;
        }

        public SqlParameter[] GetPIDDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_JOINTINGCHECK_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_STARTTIME, SqlDbType.DateTime,8),
                    new SqlParameter(PARM_STOPTIME, SqlDbType.DateTime,8),
                };
            return parms;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_JOINTINGCHECK_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_JOINTINGCHECK_RECORDTIME, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_JOINTINGCHECK_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_JOINTINGCHECK_USERID, SqlDbType.NVarChar, 10),
                    new SqlParameter(PARM_JOINTINGCHECK_FAILURENAME, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_JOINTINGCHECK_RESPONSEUSER,SqlDbType.NVarChar,10),
                };
            return parms;
        }

        public override void SetParameters(JointingCheckInfo jointingCheck, params SqlParameter[] Parms)
        {
            Parms[0].Value = jointingCheck.ProductSN;
            Parms[1].Value = jointingCheck.RecordTime;
            Parms[2].Value = jointingCheck.ProductTypeID;
            Parms[3].Value = jointingCheck.UserID;
            Parms[4].Value = jointingCheck.FailureName;
            Parms[5].Value = jointingCheck.ResponseUser;
        }
        #endregion
    }
}
